/*
 * @Date: 2023-01-22 02:17:37
 * @LastEditors: 恶名扬 2080156129@qq.com
 * @LastEditTime: 2023-01-24 05:39:34
 * @FilePath: \campus-repair-platform\server\routes\manage\grade.js
 */
const express = require("express")
// 创建路由对象
const router = express.Router()

const gradeService = require("../../service/manage/grade")
// 验证表单中间件
const expressJoi = require('@escook/express-joi')
// 导入需要的验证规则对象
const { id_p_schema } = require("../../schema/common")
const {
  list_schema,
  add_schema,
  update_schema,
} = require("../../schema/manage/grade")


router.use((req, res, next) => {
  if (req.auth?.type === 3 || req.auth?.type === 4) next() // pass control to the next handler
  else res.errSend("没有权限访问", 10002)
})

// 获取年级列表
router.get(
  "/",
  expressJoi(list_schema),
  gradeService.getGradeList
)
// 添加年级
router.post(
  "/",
  expressJoi(add_schema),
  gradeService.addGrade
)
// 修改年级信息
router.patch(
  "/",
  expressJoi(update_schema),
  gradeService.updateGrade
)
// 删除年级
router.delete(
  "/:id",
  expressJoi(id_p_schema),
  gradeService.deleteGrade
)

module.exports = router
